<template>
  <div class="home">
    <div class="article-page" v-if="articles">
      <div v-for="item in articles" :key="item.id" class="article-item" @click="goDetail(item.id)">
        <div class="head">
          <img :src="item.creatorAvatar" alt="" />
          <div class="con">
            <p class="title">{{ item.stem }}</p>
            <p class="other">{{ item.creatorName }} | {{ item.createdAt }}</p>
          </div>
        </div>
        <div class="body">{{ item.content }}</div>
        <div class="foot">
          点赞 {{ item.likeCount }} | 浏览 {{ item.views }}
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "Index",
  data() {
    return {
      articles: [],
    };
  },
  props: {
    keepAlive: {
      type: Boolean,
    }
  },
  created() {
    this.getData();
    // console.log(this.keepAlive,123);
    // console.log(this,123);
    // console.log(this.$route.meta,123);
  },
  activated() {
    console.log('activated')
  },
  deactivated() {
    console.log('deactivated')
  },
  computed: {},
  methods: {
    async getData() {
      const res = await this.$axios({
        url: "https://mock.boxuegu.com/mock/3083/articles",
      });
      this.articles = res.data.result.rows;
    },
    goDetail(id) {
      this.$router.push({
        name: "detail",
        params: {
          id,
        },
      });
    },
  },
};
</script>
<style lang='less'  scoped>
.head {
  img {
    width: 50px;
    height: 50px;
  }
  display: flex;
}
.foot {
  margin-top: 5px;
}
.article-item {
  margin-bottom: 20px;
  border: 10px solid #ff0000;
  animation: changeColor 2s infinite;
}
@keyframes changeColor {
  0% {
    border-color: #00e1ff; /* 红色 */
  }
  25% {
    border-color: #59db0d; /* 蓝色 */
  }
  50% {
    border-color: #ffa500; /* 橙色 */
  }
  75% {
    border-color: #eafa0a; /* 灰色 */
  }
  100% {
    border-color: #ff06d5; /* 红色 */
  }
}
</style>
